package c.e.b.h.e.k;

import c.e.a.a.f.i;
import c.e.a.a.f.j;
import c.e.a.a.f.k;
import c.e.a.b.b.j.d;
import c.e.a.b.g.h;
import c.e.b.h.e.l.b;
import c.e.b.h.e.m.v;
import c.e.b.h.e.m.v.e;
import c.e.b.h.e.o.g;
import c.e.b.h.e.r.a;
import c.e.b.h.e.r.c;
import java.io.File;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.Executor;

/* compiled from: SessionReportingCoordinator */
public class w0 {
    public final i0 a;
    public final g b;
    public final c c;
    public final b d;
    public final y0 e;

    public w0(i0 i0Var, g gVar, c cVar, b bVar, y0 y0Var) {
        this.a = i0Var;
        this.b = gVar;
        this.c = cVar;
        this.d = bVar;
        this.e = y0Var;
    }

    public c.e.a.b.g.g<Void> a(Executor executor, m0 m0Var) {
        w0 w0Var = this;
        m0 m0Var2 = m0Var;
        e eVar = e.NATIVE;
        c.e.b.h.e.b bVar = c.e.b.h.e.b.a;
        if (m0Var2 == m0.NONE) {
            bVar.b("Send via DataTransport disabled. Removing DataTransport reports.");
            w0Var.b.b();
            return d.b(null);
        }
        g gVar = w0Var.b;
        List e = gVar.e();
        ArrayList arrayList = new ArrayList();
        arrayList.ensureCapacity(((ArrayList) e).size());
        Iterator it = ((ArrayList) gVar.e()).iterator();
        while (it.hasNext()) {
            File file = (File) it.next();
            try {
                arrayList.add(new c(g.i.f(g.j(file)), file.getName()));
            } catch (IOException e2) {
                StringBuilder stringBuilder = new StringBuilder();
                stringBuilder.append("Could not load report file ");
                stringBuilder.append(file);
                stringBuilder.append("; deleting");
                bVar.c(stringBuilder.toString(), e2);
                file.delete();
            }
        }
        ArrayList arrayList2 = new ArrayList();
        it = arrayList.iterator();
        while (it.hasNext()) {
            e eVar2;
            j0 j0Var = (j0) it.next();
            v a = j0Var.a();
            if (a.h() != null) {
                eVar2 = e.JAVA;
            } else if (a.e() != null) {
                eVar2 = eVar;
            } else {
                eVar2 = e.INCOMPLETE;
            }
            if (eVar2 != eVar || m0Var2 == m0.ALL) {
                c cVar = w0Var.c;
                Objects.requireNonNull(cVar);
                v a2 = j0Var.a();
                h hVar = new h();
                c.e.a.a.d dVar = cVar.a;
                c.e.a.a.b bVar2 = c.e.a.a.b.HIGHEST;
                Objects.requireNonNull(a2, "Null payload");
                a aVar = new a(hVar, j0Var);
                i iVar = (i) dVar;
                j jVar = iVar.e;
                c.e.a.a.f.h hVar2 = iVar.a;
                Objects.requireNonNull(hVar2, "Null transportContext");
                String str = iVar.b;
                Objects.requireNonNull(str, "Null transportName");
                c.e.a.a.c cVar2 = iVar.d;
                Objects.requireNonNull(cVar2, "Null transformer");
                c.e.a.a.a aVar2 = iVar.c;
                Objects.requireNonNull(aVar2, "Null encoding");
                k kVar = (k) jVar;
                c.e.a.a.f.p.e eVar3 = kVar.c;
                c.e.a.a.f.h.a a3 = c.e.a.a.f.h.a();
                e eVar4 = eVar;
                a3.b(hVar2.b());
                a3.c(bVar2);
                c.e.a.a.f.b.b bVar3 = (c.e.a.a.f.b.b) a3;
                bVar3.b = hVar2.c();
                c.e.a.a.f.h a4 = bVar3.a();
                c.e.a.a.f.a.b bVar4 = new c.e.a.a.f.a.b();
                bVar4.f = new HashMap();
                ArrayList arrayList3 = arrayList2;
                bVar4.e(kVar.a.a());
                bVar4.g(kVar.b.a());
                bVar4.f(str);
                c.e.b.h.e.r.b bVar5 = (c.e.b.h.e.r.b) cVar2;
                bVar4.d(new c.e.a.a.f.d(aVar2, c.b.g(a2).getBytes(Charset.forName("UTF-8"))));
                bVar4.b = null;
                eVar3.a(a4, bVar4.b(), aVar);
                c.e.a.b.g.g e3 = hVar.a.e(executor, new u0(this));
                ArrayList arrayList4 = arrayList3;
                arrayList4.add(e3);
                Integer num = null;
                arrayList2 = arrayList4;
                w0Var = this;
                eVar = eVar4;
                m0Var2 = m0Var;
            } else {
                bVar.b("Send native reports via DataTransport disabled. Removing DataTransport reports.");
                w0Var.b.c(j0Var.b());
            }
        }
        w0 thisR = w0Var;
        return d.g(arrayList2);
    }
}
